// 路由文件

import Vue from 'vue'
import Router from 'vue-router'
//导入 vue 和 vue-router  相当于
//<script src="vue.js">  <script src="vue-router.js">
import Login from './components/Login.vue'

// import Loginq from './components/Loginq.vue'

import Home from './components/Home.vue'
import Welcome from './components/Welcome.vue'
import Users from './components/user/Users.vue'
import Rights from './components/power/Rights.vue'
import Roles from './components/power/Roles.vue'
import Reports from './components/power/Reports.vue'

import UseStep2 from './components/user/UseStep2'
import UseStep3 from './components/user/UseStep3'
import UseStep4 from './components/user/UseStep4'

import Register from './components/Register.vue'


// 世邦的验证组件
import Verification1 from './components/ShiBang/Verification1'
import Verification2 from './components/ShiBang/Verification2'
import Verification3 from './components/ShiBang/Verification3'
import Verification4 from './components/ShiBang/Verification4'
//世邦的注册组件
import Registersetp1 from './components/ShiBang/Registersetp1'
import Registersetp2 from './components/ShiBang/Registersetp2'
import Registersetp3 from './components/ShiBang/Registersetp3'

import Registersetp4 from './components/ShiBang/Registersetp4'
import Registersetp41 from './components/ShiBang/Registersetp41'
import Registersetp42 from './components/ShiBang/Registersetp42'
//世邦的企业组件
// import Companyinfo from './components/company/Companyinfo'
// import Companyinfomsg from './components/company/Companyinfomsg'
import Companyframe from './components/company/Companyframe'
import Usersinfo from './components/company/Usersinfo'
import Usersinfo1 from './components/company/Usersinfo1'

import Companyinfochange from './components/company/Companyinfochange'
import Companyinfochangemsg from './components/company/Companyinfochangemsg'
import Rolepermissions from './components/company/Rolepermissions'
import Postconfiguration from './components/company/Postconfiguration'

//薪酬管理
import SettingRules from './components/payment/SettingRules' //设置薪酬规则
import PayAccounting from './components/payment/PayAccounting' //薪酬核算

//人员管理
import employeeList from './views/employee/employeeList'
import baseSetting from './views/employee/baseSetting'
import employeeAdd from './views/employee/employeeAdd'
import employeeImport from './views/employee/employeeImport'

//薪税管理
import salaryHistoryDetails from './views/payrollTaxManage/salaryHistoryDetails/salaryHistoryDetails'  //薪酬历史明细
import substituteSalary from './views/payrollTaxManage/substituteSalary/substituteSalary'  //代发薪酬
import taxReport from './views/payrollTaxManage/taxReport/taxReport'  //个税报表
import taxReportDetail from './views/payrollTaxManage/taxReport/taxReportDetail'  //个税报表明细
import salaryAccount from './views/payrollTaxManage/salaryAccount/salaryAccount'  //薪酬台账
import salaryAccountDetails from './views/payrollTaxManage/salaryAccount/salaryAccountDetails'  //薪酬台账明细
import salaryAccounting from './views/payrollTaxManage/salaryAccounting/salaryAccounting'  //薪酬核算
import collectDeduct from './views/payrollTaxManage/collectDeduct/collectDeduct'  //收集累计扣除数
import salaryRules from './views/payrollTaxManage/salaryRules/salaryRules'  //设置薪酬规则

//账单管理
import billManage from './views/billManage/billManage'  //账单管理

//财务
import accountDetails from './views/finance/accountDetails' //账户明细
import recharge from './views/finance/recharge'  //充值

// 首页
import index from './views/index/index'  //首页

// 添加路由规则

Vue.use(Router)

//暴露
const router = new Router({
  routes: [{
    path: '/',
    redirect: "/login"
  }, //重定向
    {
      path: '/login',
      component: Login
    }, //添加一个Login路由
    {
      path:'/register',
      component:Register
    },
    //世邦的暴露验证组件start
    {
      path:'/verification1',
      component:Verification1
    },
    {
      path:'/verification2',
      component:Verification2
    },
    {
      path:'/verification3',
      component:Verification3
    },
    {
      path:'/verification4',
      component:Verification4
    },

    //世邦的暴露验证组件end
    //世邦的暴露注册组件start
    {
      path:'/registersetp1',
      component:Registersetp1
    },
    {
      path:'/registersetp2',
      component:Registersetp2
    },
    {
      path:'/registersetp3',
      component:Registersetp3
    },
    {
      path:'/registersetp4',
      component:Registersetp4
    },
    {
      path:'/registersetp41',
      component:Registersetp41
    },
    {
      path:'/registersetp42',
      component:Registersetp42
    },

    //世邦的暴露注册组件end

    {
      path: '/home',
      component: Home,
      // redirect: '/welcome',
      children: [
        //这个链接跳到对应的组件
        //企业信息组件开始
        {
          path:'/companyinfochange', //企业注册(用户信息)
          component:Companyinfochange
        },
        {
          path:'/companyinfochangemsg',//用户信息和合同信息
          component:Companyinfochangemsg
        },
        {
          path:'/companyframe',
          component:Companyframe //组织架构
        },
        {
          path:'/usersinfo', //用户管理
          component:Usersinfo
        },
        {
          path:'/usersinfo1', //用户管理(用户的设置)
          component:Usersinfo1
        },
        {
          path:'/rolepermissions',
          component:Rolepermissions  //角色权限
        },
        {
          path:'/postconfiguration',
          component:Postconfiguration //岗位配置
        },

        //企业信息组件结束

        //S=薪酬管理
        {
          path:'/settingrules',
          component:SettingRules //薪酬设置
        },
        {
          path:'/payaccounting',
          component:PayAccounting //薪酬核算
        },

        //E=薪酬管理

        //S=人员管理
        {
          path:'/employeeList',
          component:employeeList
        },
        {
          path:'/baseSetting',
          component:baseSetting
        },
        {
          path:'/employeeImport',
          component:employeeImport
        },
        {
          path:'/employeeAdd',
          component:employeeAdd
        },
        //E=人员管理

        //S=薪税管理
        {
          path: '/salaryHistoryDetails',
          component: salaryHistoryDetails
        },
        {
          path: '/substituteSalary',
          component: substituteSalary
        },
        {
          path: '/taxReport',
          component: taxReport
        },
        {
          path: '/taxReportDetail',
          component: taxReportDetail
        },
        {
          path: '/salaryAccount',
          component: salaryAccount
        },
        {
          path: '/salaryAccountDetails',
          component: salaryAccountDetails
        },
        {
          path: '/salaryAccounting',
          component: salaryAccounting
        },
        {
          path: '/collectDeduct',
          component: collectDeduct
        },
        {
          path: '/salaryRules',
          component: salaryRules
        },
        //E=薪税管理

        //S=账单管理

        {
          path:'/billManage',
          component:billManage
        },
        //E=账单管理

        //S=财务
        {
          path:'/accountDetails',
          component: accountDetails
        },
        {
          path:'/recharge',
          component: recharge
        },
        //E=财务
        // 首页
        {
          path:'/index',
          component: index
        },

        {
          path: '/welcome',
          component: Welcome
        },
        {
          path: '/users',
          component: Users
        },
        {
          path: '/rights',
          component: Rights
        },
        {
          path: '/roles',
          component: Roles
        },
        {
          path: '/reports',
          component: Reports
        },
        {
          path: '/usestep2',
          component: UseStep2
        },
        {
          path: '/usestep3',
          component: UseStep3

        },
        {
          path: '/usestep4',
          component: UseStep4
        }

      ]
    }

  ]
})
//挂载路由导航守卫
router.beforeEach((to, from, next) => {
  // to: Route: 即将要进入的目标 路由对象
  // from: Route: 当前导航正要离开的路由  /^\-[1-9][0-9]*$/
  // next: Function: 一定要调用该方法来 resolve 这个钩子。执行效果依赖 next 方法的调用参数。
  // var patt = /Verification[0-9]{1}/
  var reg1 = new RegExp('/verification[0-9]{1}');
  var reg2 = new RegExp('/registersetp[0-9]{1}');
  // console.log(reg1.test(to.path))
  // console.log(reg2.test(to.path))
  // console.log(to.path)
  if (to.path === "/login"|| reg1.test(to.path) ||reg2.test(to.path)) return next();
  const tokenStr = window.sessionStorage.getItem('token')
  console.log(tokenStr)
  if (!tokenStr) return next('/login')
  next()
})


export default router
